﻿define([],
function () {
    'use strict';

    // The collection of selected widgets (to allow multiple selection)
    var selectedWidgets = [];

    return {

        // Adds a widget to the hash of selectedWidgets ones
        // If keepPrevious is falsy, the previous selection are removed and the deselect method is called
        select: function (widget, keepPrevious) {

            if (!keepPrevious) {

                selectedWidgets.forEach(function (w) {
                    w.deselect();
                });

                selectedWidgets.length = 0;
            }

            selectedWidgets.push(widget);
        },

        remove: function (widget) {
            selectedWidgets.forEach(function (w, i) {
                if (w === widget) {
                    selectedWidgets.splice(i, 1);
                }
            });
        }

    };
});